Skip to content

feat: stop in-progress runs with the native stop button - #347

Merged
zimeg merged 2 commits into
mainfrom
stop-button
Dec 3, 2026
Merged

zimeg merged 2 commits into
mainfrom
stop-button

Conversation

@zimeg

@zimeg zimeg commented Dec 3, 2026

Copy link
Copy Markdown
Member

Summary

This pull request adds support for the native stop button to all three support agents, following agent_session_stopped.

  • Each manifest.json subscribes to agent_session_stopped.
  • app_mentioned.py and message.py set the session to processing with agents_sessions_setStatus in place of Bolt's set_status, which calls assistant.threads.setStatus. Slack shows the stop button only for a session set to processing this way, not through the assistant.threads.setStatus compatibility bridge. The loader reads "Working..." now, since agents.sessions.setStatus doesn't take custom loading messages. After an error warning, the listeners set the session back to active, since a message no longer clears the status.
  • A new agent_session_stopped.py listener stops the thread's in-flight runs, moves the session back to active with agents_sessions_setStatus, then posts "Stopped." in the thread. Slack doesn't change the status on a stop, so the app has to.
  • app_mentioned.py and message.py register each run before setting the status. A run that was stopped posts nothing more: no reply, and no ":warning: Something went wrong" for the stop. Issue submissions from the App Home modal take the same path, so they stop the same way.
  • How each subproject stops the run:
    • claude-agent-sdk: an asyncio.Event per run. A task waits on it and calls ClaudeSDKClient.interrupt().
    • openai-agents-sdk: a threading.Event per run, checked by RunHooks before each model and tool call, since the app is sync.
    • pydantic-ai: a CancellationToken per run, passed to run_sync().
  • Tests cover the stop listener, stopped mentions and DM replies posting nothing, the active reset after an error, and that each framework receives the stop.
  • The READMEs get a "Stop button" entry under Using the App and list the new files.

The coding agents' stop handling is the reference, in the shape the starter and personal agents use (bolt-python-starter-agent#317, bolt-python-personal-agent#22). The coding agents also clear pending Approve / Deny buttons on a stop, but the support agents have no approvals, so that part is left out.

Testing

  • Run each subproject with slack run in a workspace with agent sessions.
  • DM Casey or mention it in a channel, then click the stop button while it's thinking. Confirm "Stopped." posts in the thread, the loader clears, and no reply or warning follows.
  • Send another message in the same thread and confirm Casey answers normally.
  • Submit an issue from the App Home, stop it while Casey is thinking, and confirm the same.

🤖 Generated with Claude Code

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg
zimeg requested a review from a team as a code owner December 3, 2026 21:52
@zimeg zimeg added the enhancement New feature or request label Dec 3, 2026
@zimeg zimeg self-assigned this Dec 3, 2026

@cchensh cchensh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. All three subprojects match bolt-python-personal-agent#22:

  • claude-agent-sdk uses an asyncio.Event plus an interrupt task, cancelled in finally.
  • openai-agents-sdk uses a threading.Event that StopHooks checks. An exception raised in on_tool_start escapes the run rather than reaching the model as a tool error.
  • pydantic-ai uses a CancellationToken, and RunCancelled is caught as an Exception.

Cleanup runs in finally, stopBefore scopes a stop to older runs, and a stopped run is never reported as an error. The tests pass (27/26/25), and the pydantic-ai test cancels for real through TestModel.

Nits (the first two are the same in the personal-agent twin):

  • listeners/events/agent_session_stopped.py:7-13 (each subproject) posts "Stopped." even when nothing was in flight, so a stop clicked as the reply finishes leaves the answer followed by "Stopped.".
  • openai-agents-sdk (agent/support_agent.py:123-127) only checks for a stop before the next model or tool call, so an in-flight model request still completes and is billed. The README says so accurately.
  • Runs are keyed by channel and thread, while support sessions are per user, so one person's stop cancels another's run in a shared thread. That's probably intended; a README sentence would say so.
  • A stopped first mention stores no session, so un-mentioned follow-ups in that channel thread are ignored (for example claude-agent-sdk/listeners/events/message.py:43-46) until the agent is mentioned again.

Co-authored-by: Cheng Chen <35309699+cchensh@users.noreply.github.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@zimeg

zimeg commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

🙏 Thanks @cchensh! Taken in order:

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Thanks @zimeg! Issue submissions from the App Home stop the same way as DMs and mentions, and the new README line on thread-wide stops sets the right expectation.

@zimeg

zimeg commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

🌟 Thanks for the kind reviews @mwbrooks and @cchensh!

@zimeg
zimeg merged commit b81a538 into main Dec 3, 2026
8 checks passed
@zimeg
zimeg deleted the stop-button branch December 3, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants